﻿using Microsoft.OpenApi.Models;

namespace BMS.Presentation.ServiceExtensions
{
    public static class SetSwagger
    {
        public static void AddSwaggerGenConfig(this IServiceCollection services)
        {
            services.AddSwaggerGen(x =>
            {
                //获取当前程序集目录信息
                var basePath = AppContext.BaseDirectory;

                //拼接当前的xml文件目录，后面的是：当前的API项目名.xml
                var xmlPath = Path.Combine(basePath, "BMS.Presentation.xml");//todo:Path.Combine()的作用

                //显示中文注释
                x.IncludeXmlComments(xmlPath, true);

                #region swagger接口方法分组，分组后，每个方法前要加[ApiExplorerSettings(GroupName = "v2")]属性，表示是哪一组的方法
                x.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title = "后台框架一",//大标题
                    Version = "v1",
                    Description = "一般的测试方法",
                    Contact = new Microsoft.OpenApi.Models.OpenApiContact
                    {
                        Name = "平台仓库",
                        Email = "wda@qq.com",
                        Url = new Uri("https://gitee.com/wang-dengan/backstage_-management_-system")
                    },
                });
                x.SwaggerDoc("v2", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title = "后台框架二",//大标题
                    Version = "v2",
                    Description = "泛型方法",
                    Contact = new Microsoft.OpenApi.Models.OpenApiContact
                    {
                        Name = "平台仓库",
                        Email = "wda@qq.com",
                        Url = new Uri("https://gitee.com/wang-dengan/backstage_-management_-system")
                    }
                });
                #endregion
                

            });
        }
    }
}
